<template>

  <nav-bar>
    <div slot="left" class="back" @click="backClick">
      <img src="../../../assets/img/common/back.svg" alt="">
    </div>
    <div id='DetailNavBar' class='DetailNavBar' slot="center">
      <div class="titleItem" v-for="(item, index) in titles" :class='{active:index===currentIndex}' :key="index"
        @click='colorClick(index)'>
        {{item}}
      </div>
    </div>
  </nav-bar>

</template>

<script>
  import NavBar from '../../../components/common/navbar/navbar.vue'

  export default {
    name: 'DetailNavBar',
    props: { // 父辈向子辈传参

    },
    components: { // 组件的引用
      NavBar
    },
    data() {
      return {
        titles: ['商品', '参数', '评论', '推荐'],
        currentIndex: 0,
      }
    },
    methods: { // 方法
      colorClick(index) {
        this.currentIndex = index
        this.$emit('btnClick', index)
      },
      backClick() {
        this.$router.back()
      }
    },
    computed: { // 计算属性

    },
    created() { // 实例被创建之后执行代码

    },
    mounted() { // 页面进入时加载内容

    },
    watch: { // 监测变化

    }
  }

</script>
<style scoped>
  .DetailNavBar {
    display: flex;
  }

  .titleItem {
    flex: 1;
    font-size: 15px;
  }

  .active {
    color: var(--color-high-text)
  }

  .back img {
    margin-top: 11px;
  }

</style>
